/*
 ============================================================================
 Name		: stopwatchAppUi.cpp
 Author	  : Huang.haiyang
 
     This is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
	 License as published by the Free Software Foundation; either
     version 2 of the License, or (at your option) any later version.
 
     This software is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Lesser General Public License for more details.
     
 Description : CStopwatchAppUi implementation
 ============================================================================
 */

// INCLUDE FILES
#include "..\stopwatchApp.h"
#include "..\stopwatchAppui.h"
#include "view\stopwatchView.h" 
#include "resource\stopwatch.hrh"
#include "stopwatch.hlp.hrh"

#include <stopwatch.rsg>

#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknglobalnote.h>
#include <hlplch.h>

// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CstopwatchAppUi::ConstructL()
// 
// ----------------------------------------------------------
//
void  CStopwatchAppUi::ConstructL()
	{
	BaseConstructL();

	iAppContainer = CreateStopwatchView(ApplicationRect());
	AddToStackL(iAppContainer);
	}

// ----------------------------------------------------
//  CStopwatchAppUi::~ CStopwatchAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
 CStopwatchAppUi::~ CStopwatchAppUi()
	{
	if (iAppContainer)
		{
		RemoveFromStack(iAppContainer);
		delete iAppContainer;
		}
	}

// ------------------------------------------------------------------------------
//  CStopwatchAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void  CStopwatchAppUi::DynInitMenuPaneL(TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/)
	{
	}

// ----------------------------------------------------
//  CStopwatchAppUi::HandleKeyEventL(
//	 const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------
//
TKeyResponse  CStopwatchAppUi::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/,
		TEventCode /*aType*/)
	{
	return EKeyWasNotConsumed;
	}

// ----------------------------------------------------
//  CStopwatchAppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void  CStopwatchAppUi::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
		case EAknSoftkeyExit:
		case EEikCmdExit:
			{
			Exit();
			break;
			}
		case EstopwatchCmdHelp:
			{
			CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
			HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
			break;
			}
		default:
			break;
		}
	}

CArrayFix<TCoeHelpContext>*  CStopwatchAppUi::HelpContextL() const
	{
	CArrayFixFlat<TCoeHelpContext>* array = new (ELeave) CArrayFixFlat<
			TCoeHelpContext> (1);
	CleanupStack::PushL(array);
	array->AppendL(TCoeHelpContext(KUidstopwatch, KGeneral_Information));
	CleanupStack::Pop(array);
	return array;
	}

CStopwatchView* CStopwatchAppUi::CreateStopwatchView(const TRect& aRect)
	{
	CStopwatchView* appView = new (ELeave) CStopwatchView;
	appView->SetMopParent(this);
	appView->ConstructL(aRect);	
	return appView;
	}

